<template>
  <div class="loanProducts">
    <div class="loanProacducts-ations">
      <el-button type="primary"
                 @click="addscope">
        <i class="el-icon-circle-plus-outline"></i>
        添加
      </el-button>
      <!-- <el-button type="danger" @click="removeList">
        <i class="el-icon-circle-close"></i>
        删除
      </el-button> -->
    </div>
    <div class="loanProducts-main">
      <div class="loanProducts-list">
          <el-table :data='tabledata' @selection-change='handleSelectionChange'  :header-cell-style="{'text-align':'center'}"
                  :cell-style="{'text-align':'center'}">
              <el-table-column type="selection" width="55">

              </el-table-column>
               <el-table-column label="合同适用范围名称" prop="value">
              </el-table-column>
               <el-table-column label="操作">
                   <template slot-scope="scope">
                       <div>
                           <span class="dobtn" @click="editscope(scope.row)">编辑</span>
                            <span class="dobtn" @click="deletescope(scope.row)">删除</span>
                       </div>
                    <!-- <el-button type="warning" size="mini" @click="editscope(scope.row)">编辑</el-button> -->
                   </template>
              </el-table-column>
          </el-table>
      </div>
      <el-pagination background
        layout="prev, pager, next" :total="total" @current-change="handleChangePage"
      >
      </el-pagination>
    </div>
    <Adddialog ref="adddialog" @getlist = 'getlist'></Adddialog>
    <!-- <router-view></router-view> -->
  </div>
</template>

<script>
import { getscoped, getscopeasid, deletescope } from '@/api/scope.js'
import Adddialog from './add'
import { mapMutations } from 'vuex'
export default {
  data () {
    return {
      total: 0,
      tabledata: [],
      oldeditdatado: [],
      editdata: [],
      editname: ''
    }
  },
  components: {
    Adddialog
  },
  methods: {
    ...mapMutations(['changearr']),
    // 添加范围
    addscope () {
      this.$refs.adddialog.dialogFormVisible = true
    },
    // removeList () {

    // },
    handleChangePage () {

    },
    handleSelectionChange (val) {
      console.log(val)
    },
    deletescope (data) {
      this.$confirm('此操作为删除是否继续 ?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        deletescope({
          transId: '06234022',
          accessHost: '20101',
          cifSeq: '300000454',
          id: data.id,
          value: data.value
        }).then(res => {
          if (res.data.code === '000000') {
            if (res.data.data.data) {
              this.$message({
                type: 'success',
                message: '删除成功'
              })
              this.getlist()
            } else {
              this.$message({
                type: 'warning',
                message: '有模板引用了该合同适用范围'
              })
            }
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消删除'
        })
      })
    },
    getlist () {
      getscoped({
        transId: '06234019',
        accessHost: '20101',
        cifSeq: '300000454'
      }).then(res => {
        if (res.data.code === '000000') {
          this.tabledata = res.data.data.list
        }
      })
    },
    editscope (data) {
      this.editname = data.value
      this.$refs.adddialog.id = data.id
      getscopeasid({
        scopeId: data.id,
        transId: '06234018',
        accessHost: '20101',
        cifSeq: '300000454'
      }).then(res => {
        if (res.data.code === '000000') {
          this.changearr(res.data.data.list)
          this.editdata = res.data.data.list
          this.$refs.adddialog.isedit = true
          this.$refs.adddialog.dialogFormVisible = true
        }
      })
    }
  },
  mounted () {
    this.getlist()
  }
}
</script>

<style scoped>
.loanProducts {
  width: 100%;
  height: 100%;
  position: relative;
}
.loanProducts-title {
  height: 48px;
  margin: 0 0px;
  margin-bottom: 10px;
  background: #fff;
  border-radius: 4px;
  padding-left: 16px;
  box-sizing: border-box;
}
.loanProducts-title h3 i {
  width: 4px;
  height: 16px;
  background: #5290ff;
  display: inline-block;
  margin-right: 10px;
  vertical-align: middle;
}
.loanProducts-title h3 {
  padding-left: 3px;
  font-size: 18px;
  line-height: 48px;
  font-weight: bold;
}
.loanProducts-search {
  height: 64px;
  border-radius: 4px;
  margin: 0 0px;
  background: #fff;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 0 30px;
}
.loanProducts-search-item {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
}
.template-name-lable {
  white-space: nowrap;
  margin-right: 10px;
}
.template-name >>> .el-input__inner {
  width: 146px;
  height: 40px;
}
.template-number >>> .el-input__inner {
  width: 180px;
}
.template-type >>> .el-input__inner {
  width: 180px;
}
.loanProducts-search-item >>> .el-button {
  width: 118px;
  height: 40px;
  padding: 0;
  font-size: 16px;
}
.rest-btn {
  background: rgb(242, 188, 31);
  color: #fff;
}
.rest-btn:hover {
  border-color: rgba(242, 188, 31, .6);
  color: #fff;
  background: rgba(242, 188, 31, .6);
}
.loanProacducts-ations {
  margin: 10px 0px;
  background: #fff;
  border-radius: 4px;
  height: 68px;
  display: flex;
  padding-left: 22px;
  box-sizing: border-box;
  align-items: center;
}
.loanProacducts-ations >>> .el-button {
  margin: 0 8px;
  width: 92px;
  height: 36px;
  font-size: 12px;
  padding: 0;
  line-height: 36px;
}
.loanProacducts-ations >>> .el-button span {
  display: block;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-items: center;
}
.loanProacducts-ations >>> .el-button i {
  font-size: 26px;
  margin-left: 14px;
  margin-right: 10px;
}
.loanProducts-main {
  margin: 0 0px;
}
.loanProducts-main >>> .el-table-column--selection .cell {
  text-align: center;
}
.loanProducts-main >>> .el-table thead {
  color: #101010;
  height: 68px;
  font-size: 14px;
}
.list-actions {
  display: inline-block;
  padding: 0 15px;
  line-height: 14px;
  color: #207ffd;
  cursor: pointer;
}
.is-border {
  border-right: 1px solid #d9d9d9;
}
.loanProducts-main >>> .el-pagination.is-background .el-pager li {
  background: #fff;
}
.loanProducts-main >>> .el-pagination.is-background .el-pager .active {
  background: #409eff;
}
.loanProducts-main >>> .el-pagination {
  display: flex;
  justify-content: flex-end;
}
.loanProducts-main >>> .el-pagination .btn-prev,
.btn-next {
  background: #fff;
}
.loanProducts-main >>> .el-table__row{
  height: 68px
}
.loanProducts-main >>> .el-table tr{
  height: 68px;
}
.list-actions-list{
  display: flex;
  flex-wrap: nowrap;
  white-space: nowrap;
  justify-content: center;
  align-content: center;
}
.dobtn {
    color:#207ffd;
    cursor: pointer;
    margin: 0 10px;
}
.dobtn:hover{
    color:#3d87e7;
   text-decoration: underline;
}
</style>
